package utils

import (
	"bytes"
	"encoding/json"
	"net/http"
)

func SendMsg(msg string, telegramGroupID string) (bool, error) {
	var client = &http.Client{}
	data := map[string]string{
		"chat_id":    telegramGroupID,
		"text":       msg,
		"parse_mode": "Markdown",
	}
	paramsBytes, err := json.Marshal(data)
	if err != nil {
		return false, err
	}
	url := "https://api.telegram.org/bot877239117:AAGyLedUF7ebHP9QVTbTVuJr73ybf3lBago/sendMessage"
	req, err := http.NewRequest("POST", url, bytes.NewBuffer(paramsBytes))
	if err != nil {

		return false, err
	}
	req.Header.Set("Content-Type", "application/json")

	resp, err := client.Do(req)
	if err != nil {

		return false, err
	}
	defer resp.Body.Close()

	return true, err
}
